/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//listar procesos,      ps -eo pid,comm
        //matar proceso,     kill (idproceso)
        // apagar pc,     shutdown -h now
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clientelinux;

/**
 *
 * @author vixo
 */
import java.io.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Properties;
public class ClienteLinux {

    /**
     * @param args the command line arguments
     */

    static String cadena="OS: "+System.getProperty("os.name")+"\n";
    //Esta cadena nos va a servir para ir guardando la lista de procesos que bayan siendo 
    //sacados del BufferReader ok
    
    public static void main(String[] args) throws Exception {
        DatagramSocket  ds = new  DatagramSocket();
        byte[] buf = new byte[3000];
        byte[] instruccion = new byte[100];
        DatagramPacket dp = new  DatagramPacket(buf, buf.length);
        InetAddress host = InetAddress.getByName("192.168.1.254"); //IP del server
        
        BufferedReader bp=listP();
        bp.readLine();
        String temp;
        while(true){
            temp=bp.readLine();
            if(temp==null)
                break;
            cadena+=temp+"\n";
        }
        System.out.println(cadena);
        buf = cadena.getBytes();
        DatagramPacket out = new DatagramPacket(buf, buf.length, host, 2049);
        ds.send(out);
    }
    
    //BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
    
    public static void exec(String cmd){
        try{
            Runtime.getRuntime().exec(cmd);
        }catch(IOException e){
            e.printStackTrace();
        }
    }
    
    public static BufferedReader listP(){
        try{
            Process P=Runtime.getRuntime().exec("ps -eo pid,comm");
            BufferedReader in=new BufferedReader(new InputStreamReader(P.getInputStream()));
            return in;
        }catch(IOException e){
            return null;
        }
    }

    private static DatagramPacket DatagramPacket(byte[] buffer, int length, InetAddress ipAddress, int puerto) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}